package com.simoniu.first.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "CheckVerifyCodeServlet",value="/checkVerifyCode")
public class CheckVerifyCodeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //返回的信息提示
        String messageShow="";

        //用户输入的验证码
        String userCode = request.getParameter("randomCode");

        //VerifyCodeImg存在session中的验证码
        String rightCode=null;
        Object code = request.getSession().getAttribute("code");
        if(code!=null){
            rightCode=(String) code;
        }

        //用户输入和生成验证码的比较，并生成不同的信息提示
        if(userCode.equalsIgnoreCase(rightCode)){
            System.out.println("验证成功！！！");
        }else{
            System.out.println("验证失败！！！");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

}
